/******************************************************************
 * Created by: GOH CHEE HONG                                     
 * Date of Creation: 1/Sep/2008    
 * Date of last modification: 
 *                                                                
 * Description: Change friend name
 ******************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Pbdms.Common.CryptoUtils;
using Org.BouncyCastle.Bcpg.OpenPgp;
using Org.BouncyCastle.Utilities.Encoders;

namespace Pbdms.Forms.Views
{
    public partial class FrmChangeName : Form
    {
        private string keyID;
        public FrmChangeName()
        {
            InitializeComponent();
            Pbdms.Common.Global.paintBackGround(this);
        }

        public void setNewName(string name, string keyID)
        {
            this.txtName.Text = name;
            this.keyID = keyID;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            if (txtNewName.Text.Trim().Equals(""))
            {
                MessageBox.Show("Please enter the new name");
                return;
            }
            Common.DataObject.Buddy buddy = Program.friendControl.getAFriendByKeyID(keyID);
            buddy.Name = txtNewName.Text.Trim();
            //change shared control
            Program.friendControl.changeName(buddy);
            //update database
            BusinessLogic.DataController.BuddyController.create().updateBuddyToDB(buddy);
            Program.mainForm.frmBuddiesStatus.changeName(keyID,txtName.Text, txtNewName.Text);

            try
            {
                foreach (Form frm in this.MdiParent.MdiChildren)
                {
                    try
                    {

                        Pbdms.Common.BaseClass.newForms changeFrm = (Pbdms.Common.BaseClass.newForms)frm;
                        changeFrm.changeName(keyID,this.txtName.Text.Trim(), this.txtNewName.Text.Trim());
                        
                    }
                    catch { }
                }
            }
            catch
            {


            }
            this.Close();
        }


    }
}